********************************************************************************
* Turnout, all states
********************************************************************************

use dataset_voters, clear

keep if year < 2016
tabulate year, gen(year)
forvalues j = 1(1)4 {
	gen anyfrackingXyear`j' = anyfracking*year`j'
}

areg turnout anyfracking year1-year4 anyfrackingXyear2-anyfrackingXyear4, ///
	a(anid) cl(zipcode)

preserve

	gen b = .
	replace b = _b[anyfrackingXyear2] if _n == 1
	replace b = _b[anyfrackingXyear3] if _n == 2
	replace b = _b[anyfrackingXyear4] if _n == 3

	gen se = .
	replace se = _se[anyfrackingXyear2] if _n == 1
	replace se = _se[anyfrackingXyear3] if _n == 2
	replace se = _se[anyfrackingXyear4] if _n == 3

	gen index = _n
	keep if !mi(b)
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			xlab(1 "2004" 2 "2008" 3 "2012")
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lpat(solid) lcol(gray))
			xtitle("Year")
			ytitle("Difference, ever-never fracked")
			title("All states")
			name(g1, replace)
			xline(1.5, lpat(dash) lcol(black))
			;

	#delimit cr

restore


********************************************************************************
* Turnout, high-fracking states
********************************************************************************

areg turnout anyfracking year1-year4 anyfrackingXyear2-anyfrackingXyear4 ///
	if highf == 1, a(anid) cl(zipcode)

preserve

	gen b = .
	replace b = _b[anyfrackingXyear2] if _n == 1
	replace b = _b[anyfrackingXyear3] if _n == 2
	replace b = _b[anyfrackingXyear4] if _n == 3

	gen se = .
	replace se = _se[anyfrackingXyear2] if _n == 1
	replace se = _se[anyfrackingXyear3] if _n == 2
	replace se = _se[anyfrackingXyear4] if _n == 3

	gen index = _n
	keep if !mi(b)
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			xlab(1 "2004" 2 "2008" 3 "2012")
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lpat(solid) lcol(gray))
			xtitle("Year")
			ytitle("Difference, ever-never fracked")
			title("High-Fracking States")
			name(g2, replace)
			xline(1.5, lpat(dash) lcol(black))
			;

	#delimit cr

restore

********************************************************************************
* Donors, all states
********************************************************************************

use dataset_donors, clear

tabulate year, gen(year)
forvalues j = 2(1)8 {
	gen anyfrackingXyear`j' = anyfracking*year`j'
}

areg ltotamount anyfracking year2-year8 anyfrackingXyear2-anyfrackingXyear8, ///
	a(cid) cl(zipcode)

preserve

	gen b = .
	gen se = .
	forvalues i=2(1)8 {
		replace b = _b[anyfrackingXyear`i'] if _n == `i' - 1
		replace se = _se[anyfrackingXyear`i'] if _n == `i' - 1
	}

	gen index = _n
	keep if !mi(b)
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			xlab(1 "2002" 2 "2004" 3 "2006"
			4 "2008" 5 "2010" 6 "2012" 7 "2014")
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lpat(solid) lcol(gray))
			xtitle("Year")
			ytitle("Difference, ever-never fracked")
			title("All States")
			name(g3, replace)
			xline(2.5, lpat(dash) lcol(black))
			;

	#delimit cr

restore

********************************************************************************
* Donors, high-fracking states
********************************************************************************

areg ltotamount anyfracking year2-year8 anyfrackingXyear2-anyfrackingXyear8 ///
	if highf==1, a(cid) cl(zipcode)

preserve

	gen b = .
	gen se = .
	forvalues i=2(1)8 {
		replace b = _b[anyfrackingXyear`i'] if _n == `i' - 1
		replace se = _se[anyfrackingXyear`i'] if _n == `i' - 1
	}

	gen index = _n
	keep if !mi(b)
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se

	#delimit;

	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,
			legend(off)
			plotregion(style(none))
			xlab(1 "2002" 2 "2004" 3 "2006"
			4 "2008" 5 "2010" 6 "2012" 7 "2014")
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lpat(solid) lcol(gray))
			xtitle("Year")
			ytitle("Difference, ever-never fracked")
			title("High-Fracking States")
			name(g4, replace)
			xline(2.5, lpat(dash) lcol(black))
			;

	#delimit cr

restore

*******************************************************************************
* Combine plots
*******************************************************************************

gr combine g1 g2, rows(1) title("(a) Voted") name(G1, replace) ycommon
gr combine g3 g4, rows(1) title("(b) Log(Donations + 1)") name(G2, replace) ycommon

gr combine G1 G2, rows(2)

gr export "_output/figure3.pdf", replace
